package cc.wsyw126.java.nowcoder.sword_offer;

/**
 * Created by Administrator on 2017/4/14.
 */
public class NumberOf1Between1AndN_Solution {
    public int NumberOf1Between1AndN_Solution(int n) {
        int number = 0;
        for (int i = 1; i <= n; i++) {
            number+=numberOf1(i);
        }
        return number;
    }

    private int numberOf1(int n) {
        int number = 0;
        while (n>0){
            if (n%10 == 1){
                number++;
            }
            n/=10;
        }
        return number;
    }
}
